<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./node_modules/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>修改用户</h1>
    用户名: <input type="text" class="username"><br>
    密码: <input type="password" class="password"><br>
    <button>提交</button>
    <script>
        const id =location.search.replace('?','').split('=')[1]
        console.log(id)
        const ipt = document.querySelectorAll('input')
        const btn = document.querySelector('button')
        axios.get(`http://localhost:3000/users/${id}`).then(res => {
            var arr = res.data
            ipt[0].value = arr.username
            ipt[1].value = arr.password
        })
        btn.addEventListener('click',function(){
            axios({
                method:'put',
                url:`http://localhost:3000/users/${id}`,
                data:{username:ipt[0].value,password:ipt[1].value}
            })
            location.href='./index.html'
        })

    </script>
</body>
</html>